package T01_test_all.test17_arraylist_user;

import java.util.ArrayList;


/**
 * 用户的录入
 * 根据用户id查找信息
 */
public class T1702_user_controls {
    public static void main(String[] args) {

        ArrayList<T1701_user> list = new ArrayList<>();

        T1701_user user1 = new T1701_user("001","xiaohu","666");
        T1701_user user2 = new T1701_user("002","xiaohu","666");
        T1701_user user3 = new T1701_user("003","xiaohu","666");

        list.add(user1);
        list.add(user2);
        list.add(user3);

//        for (int i = 0; i < list.size(); i++) {
//            T1701_user us = list.get(i);
//            System.out.println(us.getId()+us.getUsername()+us.getPassword());
//        }
//        boolean bool1 =  select(list,"004");
//        System.out.println(bool1);
        int int1 =  selectIdReturnIndex(list,"003");
        System.out.println(int1);
    }

    public static boolean select(ArrayList<T1701_user> list, String id){
        for (int i = 0; i < list.size(); i++) {
            T1701_user u = list.get(i);
            String Uid = u.getId();
            if(Uid.equals(id)){
                System.out.println("存在:"+id);
                return true;
            }
        }
        System.out.println("不存在");
        return false;
    }

    public static int selectIdReturnIndex(ArrayList<T1701_user> list, String id){
        for (int i = 0; i < list.size(); i++) {
            T1701_user u = list.get(i);
            String Uid = u.getId();
            if(Uid.equals(id)){
                System.out.println("存在:"+id);
                return i;
            }
        }
        System.out.println("不存在");
        return -1;
    }

}
